package com.happyclub.lcy.controller;


import com.happyclub.lcy.service.ITeamService;
import com.happyclub.pojo.TbTourTeam;
import com.happyclub.pojo.TbUser;
import com.happyclub.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
public class TeamController  {

    @Autowired
    private ITeamService iTeamService;

//创建驴友队
    @RequestMapping(value = "addTeam")
    public String getNewTeam(Model model, TbTourTeam tourTeam,HttpSession session){
        TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();
        JsonResult jsonResult = iTeamService.newTeam(tourTeam,userId);
        model.addAttribute("jsonResult",jsonResult);
        return "index";//主页
    }
    //根据id查找驴友队
    @RequestMapping(value = "/selectTeamId/{teamId}")
    public @ResponseBody JsonResult selectTeamId(@PathVariable String teamId){
        return iTeamService.selectTourTeam(teamId);
    }
    //加入驴友队
    @RequestMapping(value = "/putTourTeam")
    public JsonResult putTourTeam(String teamId , HttpSession session){
        /*TbUser user = (TbUser)session.getAttribute("user");
       String userId =  user.getUserId();*/
        String userId="zxcnsn34sd";//测试用
        JsonResult jsonResult = iTeamService.putTourTeam(teamId, userId);
        return jsonResult;
    }
    //退出驴友队
    @RequestMapping("/delTourTeam")
    public JsonResult delTourTeam(HttpSession session,String teamId){
        /*TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/
        JsonResult jsonResult = iTeamService.deltourTeam("zxcnsn34sd",teamId);//测试用
        return jsonResult;
    }
    //提升副队队长
    @RequestMapping("getCaptain")
    public JsonResult getCaptain(String teamId, HttpSession session){
       /* TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/
        String userId="zxcnsn34sd";//测试用
        JsonResult jsonResult = iTeamService.upUserRoleByUserId(userId, teamId);
        return jsonResult;
    }

    //取消副队长/管理员
    @RequestMapping("delUserRole")
    public JsonResult delUserRoleByuserId(HttpSession session ,String teamId){
         /* TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/
        String userId="zxcnsn34sd";//测试用
        JsonResult jsonResult = iTeamService.delUserRoleByUserId(userId,teamId);
        return jsonResult;
    }
    //提升管理员
    @RequestMapping("appointLeader")
    public JsonResult appointLeader(HttpSession session,String teamId){
         /* TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/
        String userId="zxcnsn34sd";//测试用
        JsonResult jsonResult = iTeamService.appointLeader(userId,teamId);
        return jsonResult;
    }
    //获取当前用户加入的队列表
    @RequestMapping("getTourPal")
    public JsonResult getTourPal(HttpSession session){
         /* TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/
        String userId="zxcnsn34sd";//测试用
        JsonResult jsonResult = iTeamService.getAllTeamInforByUserId(userId);
        return jsonResult;
    }
    //转让驴友队大队长，只能转给驴友队里面的成员
    @RequestMapping("assignmentTourPal")
    public JsonResult assignmentTourPal(HttpSession session,String teamId ,String userId){
        /* TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/             //拿到队长的id
        userId="fa95b5cfd9ef4d0a94e0a00c0b352436";//测试用
        JsonResult jsonResult = iTeamService.assignmentTourPal(teamId,userId);
        return jsonResult;
    }


}
